﻿using System;   
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace WindowsGame1
{
    public class StateGoto : State
    {
        public Vector2 dest;
        public float speed = 100;
        public float slowDownDistance = 0;

        public StateGoto(Alien a)
            : base(a)
            {

            }

        public override bool Update(Timer t)
        {            
            Vector2 dir = dest - alien.pos;
            if ( dir.LengthSquared() > 1 )
            {
                alien.direction = Vector2.Normalize(dir);

                float s = speed;
                if (slowDownDistance > 0)
                {
                    float l = dir.Length() / slowDownDistance;
                    if (l > 1)
                        l = 1;
                    else if (l < 0)
                        l = 0;

                    s = speed * l;
                    if (s < speed * 0.2f)
                        s = speed * 0.2f;
                }
                alien.speed = s;

                return true;
            }
            else
            {
                alien.speed = 0;
                return false;
            }
         }
    }
}
